package model.effect;

import model.entity.BasicEntity;
import utilities.*;

/**
 * This class represents the effect that will level up an entity a specified number of times
 */
public class LevelUpEffect extends Effect implements Archiveable
{

	private int numLevelsGained = 1;
	
	/* --------------------------------------------------------------------------------
	 * Constructors
	   -------------------------------------------------------------------------------- */
	
	/**
	 * @param name The name of the Model
	 * @param numLevelsGained The number of levels gained (The default is 1)
	 */
	public LevelUpEffect(String name, int numLevelsGained)
	{
		super(name);
		this.numLevelsGained = numLevelsGained;
	}

	public LevelUpEffect(){}
	
	/* --------------------------------------------------------------------------------
	 * Getters and Setters
	   -------------------------------------------------------------------------------- */

	/**
	 * 
	 * @return the numLevelsGained field
	 */
	public int getNumLevelsGained()
	{
		return numLevelsGained;
	}


	/* --------------------------------------------------------------------------------
	 * Class methods
	   -------------------------------------------------------------------------------- */
	
	/**
	 * Levels up the entity the number of times specified by numLevelsGained
	 */
	@Override
	public void doEffect(BasicEntity ent)
	{
		for(int i = 0; i < numLevelsGained; i++)
		{
			ent.levelUp();
		}
	}

	@Override
	public String toString()
	{
		return super.toString() + "LevelUpEffect [numLevelsGained=" + numLevelsGained + "]";
	}
	
	public Archive save() {
		Archive archive = super.save();
		
//		archive.putAttribute("numLevelsGained", Integer.toString(this.numLevelsGained));
		
		return archive;
	}
	
	public void load(Archive archive) {
		super.load(archive);
		
//		this.numLevelsGained = Integer.parseInt(archive.getAttribute("numLevelsGained"));
	}
	
}
